<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>价目表修改</title>
<%@include file="../include/include.jsp"%>
<link rel="stylesheet" type="text/css" href="${csspath }/public.css" />
<script type="text/javascript" src="${layerPath}/jquery/jquery-1.8.3.js"></script>
<link rel="stylesheet" type="text/css"
	href="${bootstrapPath}/css/bootstrap.css" />
<script type="text/javascript" src="${bootstrapPath}/js/bootstrap.js"></script>
<script type="text/javascript"
	src="${bootstrapPath}/js/bootstrap3-validation.js"></script>
</head>
<style>
.labelShow {
	float: left;
	width: 20%;
	line-height: 30px;
	text-align: right;
}

.inputDiv {
	float: left;
	width: 50%;
}

.main {
	position: relative;
	margin: 0 auto;
	padding: 10px 10px;
	width: 570px;
	height: 350px;
}
</style>

<script type="text/javascript">
	$(function() {
		$("#editPriceForm").validation({
			icon : true
		});
		$("#exitBtn")
				.click(
						function() {
							var ticketLineId = $("#ticketLineId").val();
							var ticketDefId = $("#ticketDefId").val();
							var qticketType = $("#qticketType").val();
							var qticketName = $("#qticketName").val();
							var pager = $("#pager").val();
							parent.location.href = '${webcontext}/crmdp/dealer/coupon/toTicketLinePricePage?ticketLineId='
									+ ticketLineId
									+ "&ticketDefId="
									+ ticketDefId
									+ "&qticketType="
									+ qticketType
									+ "&qticketName="
									+ qticketName
									+ "&pager.currentPage="
									+ pager;
						});
		//修改保存
		$("#saveBtn")
				.click(
						function() {
							if ($("#editPriceForm").valid(this) == false) {
								return false;
							}
							$
									.ajax({
										url : '${webcontext}/crmdp/dealer/coupon/updateTicketLinePrice',
										type : 'post',
										data : {
											'id' : $("#id").val(),
											'ticketLineId' : $("#ticketLineId")
													.val(),
											'codeType' : $("#codeType").val(),
											'code' : $("#code").val(),
											'value' : $("#value").val(),
											'price' : $("#price").val()
										},
										success : function(data) {
											if (data.code == true) {
												jAlert(
														data.msg,
														"提示",
														function() {
															var ticketLineId = $(
																	"#ticketLineId")
																	.val();
															var ticketDefId = $(
																	"#ticketDefId")
																	.val();
															var qticketType = $(
																	"#qticketType")
																	.val();
															var qticketName = $(
																	"#qticketName")
																	.val();
															var pager = $(
																	"#pager")
																	.val();
															parent.location.href = '${webcontext}/crmdp/dealer/coupon/toTicketLinePricePage?ticketLineId='
																	+ ticketLineId
																	+ "&ticketDefId="
																	+ ticketDefId
																	+ "&qticketType="
																	+ qticketType
																	+ "&qticketName="
																	+ qticketName
																	+ "&pager.currentPage="
																	+ pager;
														});
											} else if (data.code == false) {
												jAlert(data.msg, "提示");
											}
										},
										error : function() {
											jAlert("服务器错误，请联系管理员", "提示");
										},
									});
						});

	});

	window.onload = function() {
		var code = '${mealPriceModel.code}';
		if (code != null && code != "") {
			$("#code").val(code);
		}
	};

	//格式化金额，保留两位小数点
	function fmoney(s, n) {
		n = n > 0 && n <= 20 ? n : 2;
		s = parseFloat((s + "").replace(/[^\d\.-]/g, "")).toFixed(n) + "";
		var l = s.split(".")[0].split("").reverse(), r = s.split(".")[1];
		t = "";
		for ( var i = 0; i < l.length; i++) {
			//t += l[i] + ((i + 1) % 3 == 0 && (i + 1) != l.length ? "," : "");
			t += l[i] + ((i + 1) % 3 == 0 && (i + 1) != l.length ? "" : "");
		}
		return t.split("").reverse().join("") + "." + r;
	}

	function changePrice() {
		var price = $("#price").val();
		if (price != null && price != "") {
			$("#price").val(fmoney(parseFloat(price), 1));
		}
	}
</script>
<body>
	<div class="main">
		<form:form class="form-horizontal" id="editPriceForm" method="post"
			action="" modelAttribute="dto" role="form">
			<input type="text" id="id" name="id" value="${id}" class="hidden" />
			<input type="text" id="ticketDefId" name="ticketDefId"
				value="${ticketDefId}" class="hidden" />
			<input type="text" id="ticketLineId" name="ticketLineId"
				value="${ticketLineId}" class="hidden" />
			<input type="text" id="codeType" name="codeType"
				value="${mealPriceModel.codeType}" class="hidden" />

			<input type="text" class="hidden" id="qticketType" name="qticketType"
				value="${qticketType}" />
			<input type="text" class="hidden" id="qticketName" name="qticketName"
				value="${qticketName}" />
			<input type="text" class="hidden" id="pager" name="pager.currentPage"
				value="${currentPage}">

			<div class="form-group">
				<label for="code" class="col-sm-2 control-label labelShow">门店属性</label>
				<div class="col-sm-5 inputDiv">
					<input type="text" class="form-control" id="codeValue"
						value="${codeValue}" check-type="required" readonly /> <input
						type="text" class="form-control hidden" id="code"
						value="${mealPriceModel.code}" check-type="required" readonly />
				</div>
			</div>
			<div class="form-group">
				<label for="value" class="col-sm-2 control-label labelShow">属性值</label>
				<div class="col-sm-5 inputDiv">
					<input type="text" class="form-control" id="value"
						value="${mealPriceModel.value}" check-type="required" readonly/>
				</div>
			</div>
			<div class="form-group">
				<label for="price" class="col-sm-2 control-label labelShow">价格</label>
				<div class="col-sm-5 inputDiv">
					<input type="text" class="form-control text-right" id="price"
						value="${mealPriceModel.price}" onchange="changePrice()"
						check-type="number3" />
				</div>
			</div>
			<div class="form-group text-center" style="margin-left: -100px;">
				<div class="col-sm-offset-2 col-sm-10">
					<button type="button" class="btn btn-success" id="saveBtn">保存</button>
					<button type="button" class="btn btn-success" id="exitBtn">取消</button>
				</div>
			</div>
		</form:form>
	</div>
</body>
</html>